<template>
	<view class="container">

		<u--form labelPosition="left" ref="form1" :model='shopInfo' :rules="rules">
				<u-overlay opacity="0" :zIndex='500' :show="overlay" @click="noLogin"></u-overlay>
			<u-form-item labelWidth="80" label="店铺" prop="viewShopListItem.shop_name" ref="item1">
  
				<u-input 
				placeholder="请选择店铺"
				:disabled='true'
				border="bottom" 
				v-model="viewShopListItem.shop_name" 
				@change="change"> 
			 
				</u-input>
				 		 
			</u-form-item>
		 <u-form-item labelWidth="80" label="条形码" prop="bar_code" ref="item1">
		  <!-- 注意：由于兼容性差异，如果需要使用前后插槽，nvue下需使用u--input，非nvue下需使用u-input -->
		  			<!-- #ifndef APP-NVUE -->
		  			<u-input placeholder="商品条形码 "
		  							
		  							border="bottom" 
		  							v-model="shopInfo.bar_code" 
		  							@change="change">
		  			<!-- #endif -->
		  			<!-- #ifdef APP-NVUE -->
		  			<u--input placeholder="商品条形码 "
		  						
		  						border="bottom" 
		  						v-model="shopInfo.bar_code" 
		  						@change="change">
		  							>
		  			<!-- #endif -->
		  				<template slot="suffix"> 
		  					<u-button
		  						@tap="scanCode"
		  						 text="扫码"
		  						type="success"
		  						size="mini"
		  					></u-button>
		  				</template>
		  			<!-- #ifndef APP-NVUE -->
		  			</u-input>
		  			<!-- #endif -->
		  			<!-- #ifdef APP-NVUE -->
		  			</u--input>
		  			<!-- #endif -->
		 	 
		 </u-form-item>
			  
	  

			<u-form-item labelWidth="80" label="商品名称" prop='goods_name'>
				<u--input placeholder="请输入商品名称"  border="bottom"  
				v-model="shopInfo.goods_name" @change="change"></u--input>
			</u-form-item>
			<u-form-item labelWidth="80" label="批次号" >
				<u--input placeholder="请输入批次号"  border="bottom"  
				v-model="shopInfo.batch_number" @change="change"></u--input>
			</u-form-item>
			<u-form-item labelWidth="80" label="保质期"  prop='quality_guarantee_period'>
				<u-row>
					<u-col span="9">
						<u--input placeholder="自定义"  border="bottom"  v-model="shopInfo.quality_guarantee_period" @change="change"></u--input>
					</u-col>
					<u-col span="2">
						<u-button type="primary"   size="small" text="选择" @click="qualityDateShow = true"></u-button>
					</u-col>
				</u-row>
			</u-form-item>
			<u-form-item labelWidth="80"  @click="show = true" label="生产日期" prop='manufacture_date'>
				<u--text v-if="!shopInfo.manufacture_date" mode="text" text="选择日期 "></u--text>
				<u--text v-else mode="date" :text="shopInfo.manufacture_date "></u--text>
				<u-datetime-picker ref="datetimePicker"  :maxDate='new Date().getTime()'    :show="show" :value="value1" closeOnClickOverlay
					@confirm="confirm" @cancel="cancel" @change="change"  mode="date"
					:formatter="formatter"></u-datetime-picker>

			</u-form-item>
			<u-form-item labelWidth="80" @click="picker2 = true" label="过期日期" prop='expiration_date'>

				<u--text v-if="!shopInfo.expiration_date" mode="text" text="选择日期 "></u--text>
				<u--text v-else mode="date" :text="shopInfo.expiration_date "></u--text>

				<u-datetime-picker ref="datetimePicker" :minDate='new  Date().getTime()' :show="picker2" :value="value1" closeOnClickOverlay
					@confirm="confirm" @cancel="cancel" @change="timePickerTwoChange"  mode="date"
					:formatter="formatter"></u-datetime-picker> 
			</u-form-item>
			<u-form-item labelWidth="80" label="库存" prop='buy_number'>
				<u-row>
					<u-col span="5">
						<u-number-box v-model="shopInfo.buy_number" ></u-number-box>
					</u-col>
					<u-col span="4">
					<u--input   border="bottom"  v-model="shopInfo.unit" placeholder='单位' ></u--input>	
					</u-col>
				</u-row>
				 
			</u-form-item>
			<u-form-item labelWidth="80" label="进货价格" prop='price'>
				<u--input placeholder="请输入进货价格 "  border="bottom"  v-model="shopInfo.price"></u--input>
				<text>单位：RMB(元)</text>
			</u-form-item>
			<u-form-item labelWidth="80" label="零售价格" prop='retail_price'>
				<u--input placeholder="请输入零售价格 "  border="bottom"  v-model="shopInfo.retail_price"></u--input>
			<text>单位：RMB(元)</text>
			</u-form-item>
			<u-form-item labelWidth="80" label="商品规格" prop='specifications'>
				<u--input placeholder="请输入商品规格"  border="bottom"  v-model="shopInfo.specifications"></u--input>
			</u-form-item>
			<u-form-item labelWidth="80" label="商品品牌" prop='product_brand'>
				<u--input placeholder="请输入品牌"  border="bottom"  v-model="shopInfo.product_brand"></u--input>
			</u-form-item>
			<u-form-item labelWidth="80"  label="生产厂家" prop='manufacturer'> 
				<u--input id="manufacturer" @blur='manufacturerBlur' @focus='manufacturerFocus' placeholder="请输入厂家"  border="bottom"  v-model="shopInfo.manufacturer" @change="changeManufacturer"></u--input>
			
			</u-form-item>
			 
				<u-row>
					<u-col span="6" offset="3">
						<view   style="height: 300rpx; " v-if="manufacturerShow && FmanufacturerList.length > 0 && manufacturerList.length > 0"  >
							 <u-list @scrolltolower="scrolltolower">
								 <u-list-item 
								 v-for="(item, index) in manufacturerList || FmanufacturerList"
												:key="index"
												v-if="index < 3"
												>
												<!-- <u--text align='center' style="border: 1px solid;" :text='item.manufactor'></u--text> -->
											<u-cell :name='item.manufactor' @click="manufacturerChoolse" :title='item.manufactor'></u-cell>
									 
								 </u-list-item>
							 </u-list>
						</view> 
					</u-col>
				</u-row>
			
 
			<u-form-item labelWidth="80" label="商品类别" prop='goods_type'>
				<u--input placeholder="请输入商品类别"  border="bottom"  v-model="shopInfo.goods_type" @change="change"></u--input>
			</u-form-item> 
			<u-form-item labelWidth="80" label="货架号" prop="goods_shelves_name" ref="item1">
			 <!-- 注意：由于兼容性差异，如果需要使用前后插槽，nvue下需使用u--input，非nvue下需使用u-input -->
			 			<!-- #ifndef APP-NVUE -->
			 			<u-input placeholder="请选择货架号"
			 							:disabled='true'
			 							border="bottom" 
			 							v-model="shopInfo.goods_shelves_name" 
			 							@change="change">
			 			<!-- #endif -->
			 			<!-- #ifdef APP-NVUE -->
			 			<u--input placeholder="请选择货架号"
			 						:disabled='true'
			 						border="bottom" 
			 						v-model="shopInfo.goods_shelves_name" 
			 						@change="change">
			 							>
			 			<!-- #endif -->
			 				<template slot="suffix"> 
			 					<u-button
			 					@tap="getCode"
			 					 text="选择货架"
			 					type="success"
			 					size="mini"
			 					></u-button>
			 				</template>
			 			<!-- #ifndef APP-NVUE -->
			 			</u-input>
			 			<!-- #endif -->
			 			<!-- #ifdef APP-NVUE -->
			 			</u--input>
			 			<!-- #endif -->
				 
			</u-form-item>
			<u-form-item label="图片" prop="picture" borderBottom ref="item1">
			<u-upload
				:fileList="fileList1"
				@afterRead="afterRead"
				@delete="deletePic"
				name="1"
				:multiple='false'
				
				:maxCount="1"
			></u-upload>
					
			</u-form-item>
		</u--form>

		<u-row  customStyle="margin-top:32rpx">
		 
			<u-col span="8" offset="2"  >
		 
				<u-button  shape='circle' text="保存-已录商品信息" size="success" type="info" @click="$util.debounce(saveShop,1000)" ></u-button>
		 
			</u-col>
			 
		</u-row>
		<view class="u-content u-m-t-300">
			<u--text text='提示:' color='#D71717'></u--text>
			<u--text class="u-m-t-10" text='1.若商品信息不完整,系统会自动补充缺省信息,时间大约在3天以内;' color='#D71717'></u--text>
			<u--text class="u-m-t-10" text='2.对于商品有效期为空,您可以手动录入商品有效期天数;' color='#D71717'></u--text>
			<u--text class="u-m-t-10" text='3.快速录入时,只需要设置商品还有多少天过期即可,其他交给系统自动完成吧!' color='#D71717'></u--text>
			<!-- <u-parse :content="content"></u-parse> -->
		</view>
			<u-popup mode='right' :show="schooseShelf" @close="schooseShelf = false"   >
				
				<view style="width: 400rpx;padding: 30rpx;">
					<u--input
							placeholder="搜索"
							@change = 'shelf'
							prefixIcon="search"
							prefixIconStyle="font-size: 22px;color: #909399"
						></u--input>
					 <u-row customStyle="margin-top: 15rpx;"   v-for="(item,index) in fillterShelfList"  :key="index">
						 <u-col span="8">
							 
							 <u--text :text="item.shelves_name">
								 
							 </u--text>
						 </u-col>
						 <u-col span="4">
							 <u-button type="primary" size="small" text="选择" @click="shopInfo.goods_shelves_id = item.id;shopInfo.goods_shelves_name = item.shelves_name "></u-button>
						 </u-col>
					 </u-row>
					 <u-row customStyle="margin:  20rpx 0;"  v-if="fillterShelfList.length == 0">
						 <u-col span="10"  offset="1">
							 <u-button type="primary" text="添加货架" @click="addShelf"></u-button>
						 </u-col>
					 </u-row>
				</view> 
			</u-popup>
		<u-picker :show="qualityDateShow" ref="uPicker" :columns="qualityDate" @change="qualityDateChange" @cancel= 'qualityDateShow = false'  @confirm="qualityDateShow = false"></u-picker>
	</view>
</template>

<script>
 var that
 import mInit from "../../../tools/Init"
 var ERGoodsScan = require('../../../service/ERGoodsScan'),mERGoodsScan
 var ERgoodsShelf = require('../../../service/ERgoodsShelf'),mERgoodsShelf
 import initMixin  from '../../../static/js/initMixin.js' ;
	export default {
		mixins: [
				  initMixin
				],
		data() {
			return { 
				FmanufacturerList: [],
				manufacturerList:[],
				manufacturerShow:false,
				manufacturerTop:0,
				viewShopListItem:{},
				fileList1:[],
				cShelfsId:{
					id:0,
					 
				},
				shelfList:[],
				schooseShelf:false,
				 
				shopInfo:{ 
					own_store_id:0,//店铺id
					shop_name:'',
					unit:'个',
					bar_code: '',
					goods_name: '',
					buy_number: 0,
					batch_number:'',
					quality_guarantee_period: '  ',
					product_brand: '',
					manufacturer: '',
					goods_type: '',
					manufacture_date: '', 
					expiration_date: '',
					specifications: '',
					price:null,
					retail_price:null,
					goods_shelves_name:'',
					goods_shelves_id:0,
					statue:0,
					picture:'',
					 
				},
				rules:{
					goods_name :{
						type: 'string',
						required: true,
						message: '输入名称',
						trigger: ['blur', 'change']
					}, shop_name:{
						type: 'string',
						required: true,
						message: '请选择店铺',
						trigger: ['blur', 'change']
					},goods_shelves_name:{
							type: 'string',
							required: true,
							message: '请选择货架',
							trigger: ['blur', 'change']

					},quality_guarantee_period:{
							type: 'string',
							required: true,
							message: '请输入保质期',
							trigger: ['blur', 'change']
					
					} 
				},
				overlay:true,
				fillterShelfList:[],
				value2: 30,
				show: false,
				myShop:false,
				picker2: false,
				value1: Number(new Date()),
				textscan: '扫码',
				typescan: 'scan-listener',
				title: 'Hello-plusScan',
				value: '',
				isLogin:false,
				userInfo:{},
				shopList:[],
				qualityDateShow:false,
				goodsLimit:false,
			  
			}
			
		},
		computed:{
			qualityDateDay(){
				let day = []
				let month = []
				let year = []
				day.push(' ')
				month.push(' ')
				year.push(' ')
				for(let i =1;i< 31 ;i++){
					day.push(i + '天')
					if(i < 7){
						year.push(i + '年')
					}
					 if(i <= 12){
						month.push(i+'月')
					}
				}
				year.push('永久')
			 
				 return [year,month,day]
			},
		 
			qualityDate(){  
			 
				return this.qualityDateDay
			}
		},
		onLoad() {
			that = this
			mERGoodsScan = new ERGoodsScan(this.mNetTool)
			mERgoodsShelf = new ERgoodsShelf(this.mNetTool)
			 mInit.init(this.mNetTool, res => {
			 	let userInfo = uni.getStorageSync('userInfo')
			 	if(userInfo){
			 		that.userInfo = userInfo
					if(userInfo.level != 2){
						this.checkGoodsLength()//检查商品条数
					}
			 	} 
				 
			 	this.loadData();
				 
			 })  
		},
		mounted() { 
			that.shopList = uni.getStorageSync('shopList')
			let userInfo = uni.getStorageSync('userInfo')
			
			
			that.userInfo = userInfo
			if(!userInfo){
				this.isLogin = false
				return
			}else{
				this.isLogin = true
			}
		 
			let addInfo = {
					store_id:userInfo.store_id,
			}
			// mERgoodsShelf.list(addInfo,res => {
			// 	console.log(res)
			//  that.fillterShelfList = res.rows 
			// 	that.shelfList = res.rows 
			// }) 
			
			 
		},
		onShow() {
			
			let isLogin =  uni.getStorageSync('isLogin')
			if(isLogin){
				this.overlay = false
			}
			//条形码 扫码快捷输入
			let shopCode = uni.getStorageSync('shopCode')
			if(shopCode){
				mERGoodsScan.list({ 
						// own_store_id: that.shopId
						bar_code:shopCode 
					},res =>{
						that.shopInfo = res.rows[0]
						uni.removeStorageSync('shopCode')
					})
			}
			let viewShopListItem = uni.getStorageSync('viewShopListItem')
			if(viewShopListItem){
				that.viewShopListItem = viewShopListItem
			}
			if(!that.viewShopListItem) {
				that.viewShopListItem = that.shopList[0]
				uni.setStorageSync('viewShopListItem',that.shopList[0])
				
			}
			// 获取当前店铺的货架 
			let shelfLit = uni.getStorageSync('shelfList')
			if(shelfLit){
				that.shelfList = shelfLit
				that.fillterShelfList = that.shelfList.filter(item => {
					return item.store_id == that.viewShopListItem.id
				}) 
			}
			
		},
		onReady() {
			 this.$refs.datetimePicker.setFormatter(this.formatter)
			uni.$on(this.typescan, (data) => {
				this.shopCode = data.result
			})
		},
		methods: {
			
			checkGoodsLength(){
				//商品上限查询
				mERGoodsScan.list({ 
						own_store_id: that.shopId
					},res =>{
						if(res.records >= 500){
							that.goodsLimit = true
						}
					})
			},
			qualityDateConfirm(e){
				console.log(e)
			},
			qualityDateChange(e){  
				let year = 0
				let month =0
				let day = 0
				if(e.value[0] != '永久'){
					
					console.log(typeof parseInt(e.value[1]))
					if( !isNaN(parseInt(e.value[0]))) {
						 year = parseInt(e.value[0])
					}
					 
					if(!isNaN(parseInt(e.value[1]))) {
						 month = parseInt(e.value[1])
					}
					
					if( !isNaN(parseInt(e.value[2]))) {
						 day = parseInt(e.value[2])
					}
					
					let yaerTemp = 1000*60*60*24*365
					let monTemp = 1000*60*60*24*30
					let dayTemp = 1000*60*60*24
					let newQualityTime  =  yaerTemp*year + monTemp*month + dayTemp*day + new Date().getTime()
					let QualityTime = new Date(newQualityTime)
					console.log(QualityTime)
					console.log( QualityTime.getFullYear() + '-' + QualityTime.getMonth() + '-' + QualityTime.getDate())
					that.shopInfo.expiration_date =  newQualityTime
				 
				} 
				 const {
					columnIndex,
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e
				console.log('qualityDateChange' )
				
				let a = 365*year + month*30 + day
				// e.value.forEach(item => { 
				// 		a+=item
					 
				// }) 
				// let addTime = a
				
				// if (addTime.indexOf('年') != -1) {
				//   addTime = addTime.replace("年", "/")
				// }
				// if (addTime.indexOf('月') != -1) {
				//   addTime = addTime.replace("月", "/")
				// }
				// if (addTime.indexOf('日') != -1) {
				//   addTime = addTime.replace("日", "")
				// }
				// let newTime = new Date().getTime()
				// let netxTime = new Date(addTime).getTime()
				// // let newQualityTime = new Date(newTime + netxTime)
				  
				// console.log( newTime,netxTime  )
				// let ms = e.value
				that.shopInfo.quality_guarantee_period  = a + '天'
			},
			manufacturerChoolse(e){
				console.log(e)
				that.manufacturerShow = false
				that.shopInfo.manufacturer = e.name
				console.log('---------------------------------------')
			},
			changeManufacturer(e){
				that.manufacturerShow = true
				console.log(that.FmanufacturerList) 
				if(that.FmanufacturerList.length > 0){ 
					 that.manufacturerList =  that.FmanufacturerList.filter(item => item.manufactor.indexOf(e) != -1) 
				} 
			},
			loadData(){
			 
				let viewShopListItem = uni.getStorageSync('viewShopListItem')
				//获取厂家
				if(viewShopListItem.id){
					console.log(viewShopListItem.id)
					this.mNetTool.getAjaxUrlValueBackground('capi/V2/ER_Manufacturer/erManufacturer/list',{
						// manufactor:'',
						store_id:that.viewShopListItem.id
					},res => {
						console.log('获取厂家',res)
						that.FmanufacturerList = res.rows
					})
				}
				
			},
			manufacturerBlur(){
				setTimeout(function(){
					that.manufacturerShow = false
				},600)
				// that.manufacturerShow = false
				 
			},
			manufacturerFocus(){
				
				console.log("获取焦点www"  );
				const query = uni.createSelectorQuery().in(this);
				query.select('#manufacturer').boundingClientRect(data => {
				  console.log("得到布局位置信息" , JSON.stringify(data));
				  that.manufacturerTop = data.top
				}).exec();
			},
			noLogin(){
				this.overlay = false
				// console.log(123)
				uni.showModal({
					content: "您未登录，请先登录！",
					success(r) {
						if (r.confirm) {
							if (this.autoStatus) { //支持一键登录
								console.log('进入一键登录')
								this.keyLogin()
								
							} else {
								// #ifdef MP-WEIXIN
								uni.navigateTo({
									url: '../login/keyLogin'
								})
								// #endif
								// #ifdef APP-PLUS || H5
								uni.navigateTo({
									url: '../login/login'
								})
								// #endif
				
							}
				
						}else {
							that.overlay = true
							console.log(12)
						}
					}
				})
			},
			addShelf(){
				uni.navigateTo({
					url:'../goodsShelf/addGoodsShelf?fromScan=true'
				})
			},
			shelf(e){
				that.fillterShelfList = that.shelfList.filter(item => {
					return item.shelves_name.indexOf(e) != -1
				})
			},
			// 删除图片
			deletePic(event) {
				that[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = that[`fileList${event.name}`].length
				lists.map((item) => {
					that[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await that.uploadFilePromise(lists[i].thumb)
					let item = that[`fileList${event.name}`][fileListLen]
					that.shopInfo.picture = result.fileUrl
					that[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result.fileUrl
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				// let url = "https://test.iloomo.com/capi/tools/public/fileUpload?token=" + uni.getStorageSync('token') + "&fileName=" +'img'
				return new Promise((resolve, reject) => {
					// mUpLoadFile.uploadImg(url,res =>{
					// 	setTimeout(() =>{
					// 		// resolve(res.data.data)
					// 		console.log(res)
					// 	},1000)
					// })
					let a = uni.uploadFile({
						url: 'https://api.iloomo.com/capi/tools/public/fileUpload?token=08fee81482a84d388029f67ed57490cf', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							console.log(JSON.parse(res.data))
							setTimeout(() => {
								resolve(JSON.parse(res.data))
							}, 1000)
						}
					});
				})
			},
			changeShelf(){
					this.change(e)
					const {
						columnIndex,
						value,
						values,
						index,
						// 微信小程序无法将picker实例传出来，只能通过ref操作
						picker = this.$refs.uPicker3
					} = e
					if (columnIndex === 0) {
						picker.setColumnValues(1, this.columnData[index])
					}

			},
			confirmShelf(e){
				console.log(e.value)
			},
			getCode(){
				that.schooseShelf = true
			},
			// saveShop(){
			// 	uni.$u.throttle(this.tosaveShop, 1000)
			// },
			saveShop() { 
				let userInfo = uni.getStorageSync('userInfo')
				if(userInfo){
					let tiem = new Date().getTime()
					let endTime = new Date(userInfo.vip_end_time).getTime()
					 
					if(endTime > tiem ){
						 
					}else{
						uni.$u.toast('您的会员已过期，请充值')
						 return
					}
				}
				if(that.goodsLimit){
					uni.$u.toast('您的录入条数以上限,请升级会员。')
					return
				}
				if(!that.isLogin){
					uni.showModal({
						content:'请登录后使用',
						success(r) {
							if(r.confirm){
								uni.navigateTo({
									url:'../login/login'
								})
							}else {
								uni.navigateBack({
									
								})
							}
						}
					})
				}
				if(!that.viewShopListItem.id){
					uni.$u.toast('请选择店铺')
					uni.switchTab({
						url:'../home/home'
					})
					return
				}
				if(!that.shopInfo.expiration_date){
					uni.$u.toast('请选择过期日期')
					 
					return
				}
				console.log(that.shopInfo)
			 
			 
					that.shopInfo.employ = userInfo.real_name
				 
					that.shopInfo.created_by = userInfo.id
					that.shopInfo.status = 0//是否下架
					// 所属店铺
					that.shopInfo.own_store_id = that.viewShopListItem.id
					// 如果有错误，会在catch中返回报错信息数组，校验通过则在then中返回true
					this.$refs.form1.validate().then(res => {
						uni.showLoading({
							title:'请稍等'
						})
						this.mNetTool.getAjaxUrlValueBackground('capi/V2/ER_Manufacturer/erManufacturer/list',{
							manufactor:that.shopInfo.manufacturer,
						 
						},res => {
							console.log('厂家啊',res)
							if(res.records == 0){
								this.mNetTool.getAjaxUrlValueBackground('capi/V2/ER_Manufacturer/erManufacturer/save',{
									manufactor:that.shopInfo.manufacturer,
									store_id:that.viewShopListItem.id
								},R=> {
									this.mNetTool.getAjaxUrlValueBackground('capi/V2/ER_Manufacturer/erManufacturer/list',{
										// manufactor:'',
										store_id:that.viewShopListItem.id
									},res => {
										console.log('获取厂家111',res)
										that.FmanufacturerList = res.rows
									})
									console.log('厂家啊',R)
								})				
							}
						})
						console.log(that.shopInfo) 
						mERGoodsScan.save(that.shopInfo,res => {
							console.log(res)
							uni.$u.toast('保存成功')
							uni.hideLoading()
						})
					}).catch(errors => {
						uni.$u.toast('保存失败，请写信息不完整')
					})

				 
			},
			inputNum() {
				console.log(this.shopNum)
				if (this.shopNum < 0) {
					this.shopNum = 0
				}
			},
			scanCode() {
				console.log(222222)
				uni.navigateTo({
					url: 'plusScan/index?text=' + this.textscan + '&type=' + this.typescan
				})
			},
			close() {
				this.picker2 = false
				this.show = false
			},
			cancel() {
				this.picker2 = false
				this.show = false
			},
			timePickerTwoChange(e){
				console.log(e)
			},
			confirm(e) { 
				if (this.picker2) {
					console.log(e.value)
					let day = (new Date(e.value) -  new Date())/1000/60/60/24
					console.log(parseInt(day))
					that.shopInfo.quality_guarantee_period = parseInt(day) + '天'
					this.shopInfo.expiration_date = e.value
				} else {
					this.shopInfo.manufacture_date = e.value
				}
				// this.result(e.value, e.mode)
				this.picker2 = false
				this.show = false
			},
			change(e) {
				console.log('change', e)
			},
			navigateBack() {
				uni.navigateBack()
			},
			formatter(mode, value) {
				if (mode === 'year') {
					return `${value}年`;
				}
				if (mode === 'month') {
					return `${value}月`;
				}
				return value;
			},
			filter(mode, options) {
				if (mode === 'year') {
					return options.filter((option) => option % 2 === 0);
				}

				return options;
			},
			showDatetimePicker(index) {
				this.current = index + 1
				this.show = true
			},
			result(time, mode) {
				const timeFormat = uni.$u.timeFormat,
					toast = uni.$u.toast
				switch (mode) {
					case 'datetime':
						return toast(timeFormat(time, 'yyyy-mm-dd hh:MM'))
					case 'date':
						return toast(timeFormat(time, 'yyyy-mm-dd'))
					case 'year-month':
						return toast(timeFormat(time, 'yyyy-mm'))
					case 'time':
						return toast(time)
					default:
						return ''
				}
			},
			filter(type, options) {
				if (type === 'year') {
					return options.filter((option) => option % 2 === 0)
				}

				return options;
			}, 
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
		},
	 
		onUnload() {
			uni.$off(this.typescan)
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 32rpx;
	}
</style>
